package com.hdyg.sixg.activity.mine;

import android.text.Html;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.hdyg.sixg.R;
import com.hdyg.sixg.activity.common.BaseActivity;
import com.hdyg.sixg.entry.NoticeBean;
import com.hdyg.sixg.mvp.Contrant.CNoticeDetail;
import com.hdyg.sixg.mvp.base.BaseUrl;
import com.hdyg.sixg.mvp.base.GetParamUtil;
import com.hdyg.sixg.mvp.base.SpMsg;
import com.hdyg.sixg.mvp.presenter.PNoticeDetail;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import butterknife.BindView;

/**
 * @author CZB
 * @describe 公告详情
 * @time 2019/4/8 15:31
 */
public class NoticeDetailActivity extends BaseActivity implements CNoticeDetail.IVNoticeDetail {

    @BindView(R.id.ll_top_left)
    LinearLayout llTopLeft;
    @BindView(R.id.tvTopTitle)
    TextView tvTopTitle;
    @BindView(R.id.tv_content)
    TextView tvContent;
    @BindView(R.id.srl_refresh)
    SmartRefreshLayout srlRefresh;

    private String id;
    private CNoticeDetail.IPNoticeDetail mPresenter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_notice_detail;
    }

    @Override
    protected void initView() {
        onClickListener();
        tvTopTitle.setText(R.string.notice_detail_title);
        id = getIntent().getStringExtra(SpMsg.INTENT_STR);

    }

    private void onClickListener() {
        srlRefresh.setOnRefreshListener(refreshLayout -> {
            srlRefresh.finishRefresh(2000);//传入false表示刷新失败
            initData();
        });
        llTopLeft.setOnClickListener(v -> finish());
    }

    @Override
    protected void initData() {
        mPresenter.pGetNoticeDetail(BaseUrl.NOTICE_DETAIL_URL, GetParamUtil.getNoticeDetailParam(id));
    }

    @Override
    protected void createPresenter() {
        mPresenter = new PNoticeDetail(this);
    }

    @Override
    public void vGetNoticeDetailSuccess(NoticeBean.NoticeListBean dataBean) {
        tvContent.setText(Html.fromHtml(dataBean.getContent()));
    }
}
